package com.infore.dataReceiving.core.chain;
import java.util.ArrayList;
import java.util.List;
import com.infore.dataReceiving.core.filter.Water2018InstructionsFilter;
import com.infore.dataReceiving.dto.WaterInstructionsDto;
import com.infore.dataReceiving.repository.IBackControlLogRepository;
import com.infore.dataReceiving.util.RedisUtil;

import io.netty.channel.ChannelHandlerContext;

public class Water2018InstructionsChain implements Water2018InstructionsFilter{
	
	private List<Water2018InstructionsFilter> filters = new ArrayList<>();
	private int index=0;
	
    public Water2018InstructionsFilter addFilter(Water2018InstructionsFilter filter) {
        filters.add(filter);
        return this;
    }

	@Override
	public void doFilter(ChannelHandlerContext ctx,WaterInstructionsDto dto,
			Water2018InstructionsChain chain,RedisUtil redisUtil,IBackControlLogRepository repository, boolean interrupt) {
		if(interrupt||index==filters.size()){
        	index=0;
            return;
        }
		Water2018InstructionsFilter filter=filters.get(index);
        index++;
        filter.doFilter(ctx,dto,chain,redisUtil,repository,interrupt);
	}

}
